#include<bits/stdc++.h>
using namespace std;
const int MAXN=2010;
int n,m,head[MAXN],cnt,dfn[MAXN],low[MAXN],belong[MAXN],ind,stac[MAXN],top;
bool vis[MAXN];
struct edge
{
	int v,next;
}e[MAXN*5];
void addedge(int x,int y)
{
	e[cnt]=(edge){y,head[x]};
	head[x]=cnt++;
	return;
}
void tarjan(int u)
{
    dfn[u]=low[u]=++ind;
    vis[u]=true;
    stac[++top]=u;
    for(int i=head[u];~i;i=e[i].next)
    {
        int v=e[i].v;
        if(!dfn[v])
        {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(vis[v])low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        ++cnt;
        int i;
        do
        {
            i=stac[top--];
            vis[i]=false;
            belong[i]=cnt;
        }while(u!=i);
    }
    return;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(head,-1,sizeof(head));
		memset(belong,0,sizeof(belong));
		memset(dfn,0,sizeof(dfn));
		memset(low,0,sizeof(low));
		memset(vis,0,sizeof(vis));
		ind=top=cnt=0;
		scanf("%d%d\n",&n,&m);
		for(int i=1;i<=m;++i)
		{
			char t1,t2;
			int k1,k2,k3,k4;
			scanf("%c",&t1);
			scanf("%d ",&k1);
			scanf("%c",&t2);
			scanf("%d\n",&k2);
            if(t1=='m')k1=(k1<<1)-1;
            else k1=(k1-1)<<1;
            if(t2=='m')k2=(k2<<1)-1;
            else k2=(k2-1)<<1;
            addedge(k1^1,k2);
			addedge(k2^1,k1);
		}
        n<<=1;
        cnt=0;
        for(int i=0;i<n;++i)
            if(!dfn[i])tarjan(i);
        bool flag=false;
        for(int i=0;i<n;i+=2)
        {
            if(belong[i]==belong[i^1])
            {
                printf("BAD\n");
                flag=true;
                break;
            }
        }
        if(!flag)printf("GOOD\n");
    }
	return 0;
}
